package com.vodafone.mapreduce.dto.common;

import java.io.Serializable;

import com.vodafone.mapreduce.MapReduce;

/**
 * Generic and limited immutable DTO to store (key, value) pairs. This class cannot be named immutable, since it makes use of generic
 * attributes which might be initialized with not-immutable classes.
 */
public class KeyValuePair<K, V> implements Serializable {

    // -------------------------------------------------------------------------------------------------------------------------------------
    // Class constants.
    // -------------------------------------------------------------------------------------------------------------------------------------

    private static final long serialVersionUID = MapReduce.SERIAL_VERSION_UID;

    // -------------------------------------------------------------------------------------------------------------------------------------
    // Instance attributes.
    // -------------------------------------------------------------------------------------------------------------------------------------

    private final K k;
    private final V v;

    // -------------------------------------------------------------------------------------------------------------------------------------
    // Instance constructors.
    // -------------------------------------------------------------------------------------------------------------------------------------

    public KeyValuePair(K k, V v) {
        this.k = k;
        this.v = v;
    }

    // -------------------------------------------------------------------------------------------------------------------------------------
    // Instance methods.
    // -------------------------------------------------------------------------------------------------------------------------------------

    public K getKey() {
        return k;
    }

    public V getValue() {
        return v;
    }

    public String toString() {
        return "(" + k + ", " + v + ")";
    }

    // -------------------------------------------------------------------------------------------------------------------------------------

}
